<style lang="less">
  @import "algorithmManage";
</style>

<template>
  <div class="algorithm">
    <div class="algorithm-search">
      <algorithm-search @algorithmList="getResult"></algorithm-search>
    </div>
    <div class="algorithm-table">
      <Table border ref="selection" :columns="columns" :data="data"></Table>
    </div>
  </div>
</template>

<script>
  import AlgorithmSearch from '../../../components/algorithm-search/algorithm-search'
  import {url} from '../../../../config/url'
    export default {
        name: "algorithmManage",
      components:{
          AlgorithmSearch,
      },
      data(){
        return{
          columns: [
            {
              type: 'selection',
              width: 60,
              align: 'center'
            }, {
              title:'ID',
              key:'id',
              width:90
            },
            {
              title: '算法名',
              key: 'name',
            },
            {
              title: '描述',
              key: 'description'
            },
            {
              title:'创建者',
              key:'createTime',
            },
            {
              title: '操作',
              key: 'handle',
              width:'80px',
              render: (h, params) => {
                return h('div', [
                  //删除算法
                  h('Button', {
                    props: {
                      icon:'ios-trash'
                    },
                    on: {
                      click: () => {
                        this.remove(params.index)
                      }
                    }
                  })
                ]);
              }
            }
          ],
          data: [
          ]
        }
      },
      methods:{
        remove (index) {
          let id=JSON.stringify([this.data[index].id]);
          this.$axios.delete(url+'/algorithm',{
            params:{
              'data':id
            }
          }).then(res=>{
            console.log(res.data);
            if(res.data.error_code===0){
              this.data.splice(index, 1);
              alert("删除算法成功")
            }
            else{
              alert("删除算法失败"+res.data.error_msg)
            }
          })
        },
        //获取查询算法的结果
        getResult(data){
          this.data=data
        }
      }
    }
</script>

<style scoped>

</style>
